//函数类型：函数类型实际上指的是函数的参数与返回值
//指定参数类型
function add(a: number, b: number) {
  return a + b;
}
const num: number = add(1, 2);
console.log("num", num);
type userInfo = {
  age: number;
  name: string;
};
//指定返回值类型
const getUserInfo = (): userInfo => {
  return {
    age: 18,
    name: "张三",
  };
};
const user: userInfo = getUserInfo();
console.log("user", user);

//判断一个数字是否是偶数
const isOdd = (num: number): boolean => {
  return num % 2 === 0;
};

const result = isOdd(3);
console.log("result", result); // false

//同时给函数指定参数与返回值
//从数字数组中找到最小的数字并返回
const findMinNumber: (arr: number[]) => number = (arr) => {
  return Math.min(...arr);
};

let resNum = findMinNumber([1, 99, 2, 55, 3.14, -1]);
console.log("resNum", resNum);
